package oj;

import java.util.Scanner;

public class NewCoder_Fibonacci {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int a=scanner.nextInt();
        int fib1=0;
        int fib2=1;
        int fib3=0;
        int min = 0;
        int max=0;
        for (int i = 0; i < 50; i++) {
            fib3=fib1+fib2;
            fib1=fib2;
            fib3=fib2;

            if(fib3>a){
                min=fib3-a;
                break;
            }else {
                max=a-fib3;
            }
        }
        System.out.println(Math.min(max,min));

    }
}
